package miracom.one.MilkProduction.util;

import milkproduction.service.ProductionProcessService;

public class Impregnator extends Thread{
	private int  milkAmount;
	private int containerAmount;
	
	public Impregnator(int milkAmount,int containerAmount){
		this.milkAmount = milkAmount;
		this.containerAmount = containerAmount;
	}

	@Override
	public void run() {
		ProductionProcessService.impregnatorProgressAmount=0;//주입기 처리량 초기화
		try {
			for(int i = 0;i<milkAmount;i++){
			this.sleep(10);//용기 가저오기
			containerAmount = containerAmount-1;//용기 하나 사용
			this.sleep(10);//용기에 우유 주입
			this.sleep(10);//용기 밀봉하기
			this.sleep(10);//용기 검사 하기
			ProductionProcessService.impregnatorProgressAmount=ProductionProcessService.impregnatorProgressAmount+1;
			ProductionProcessService.packageCheck = ProductionProcessService.packageCheck +1;//9개 모으기
			System.out.println("주입기 : "+i);
			ProductionProcessService.milkAmount = ProductionProcessService.milkAmount+1;
			}
			//불량 생성 하기
			//int defective = (int)(Math.random()*10)+1;
			//System.out.println("불량수량 :"+defective);
			
			//ProductionProcessService.milkAmount = ProductionProcessService.milkAmount+1;
			
			ProductionProcessService.impregnatorWork = false; //기계 멈춤
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
